% Benchmarking L1 vs L2 norm minimization in CVX
n = 500;       % Dimension of variable
m = 300;       % Number of linear constraints

% Random problem data
A = randn(m, n);
b = randn(m, 1);

% Benchmark L1 norm minimization
fprintf('Solving L1 norm minimization...\n');
tic;
cvx_begin quiet
    variable x1(n)
    minimize(norm(x1, 1))
    subject to
        A * x1 == b
cvx_end
time_l1 = toc;
fprintf('L1 norm minimization time: %.4f seconds\n', time_l1);

% Benchmark L2 norm minimization
fprintf('\nSolving L2 norm minimization...\n');
tic;
cvx_begin quiet
    variable x2(n)
    minimize(norm(x2, 2))
    subject to
        A * x2 == b
cvx_end
time_l2 = toc;
fprintf('L2 norm minimization time: %.4f seconds\n', time_l2);

% Summary
fprintf('\nSummary:\n');
fprintf('L1 time: %.4f s | L2 time: %.4f s\n', time_l1, time_l2);
if time_l1 < time_l2
    fprintf('L1 norm was faster.\n');
else
    fprintf('L2 norm was faster.\n');
end
